<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>推送消息</title>
    <link rel="shortcut icon" href="favicon.ico">
    <link href="__CSS__/bootstrap.min.css?v=3.3.6" rel="stylesheet">
    <link href="__CSS__/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="__CSS__/animate.min.css" rel="stylesheet">
    <link href="__JS__/layui/css/layui.css" rel="stylesheet">
    <link href="__CSS__/style.min.css?v=4.1.0" rel="stylesheet">
</head>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated">
        <div class="row">
            <div class="col-sm-8 col-xs-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>推送消息</h5>
                    </div>
                    <div class="ibox-content">
                        <form class="form-horizontal m-t layui-form" id="commentForm" method="post" action="pushMessage">
                            <div class="layui-tab layui-tab-card"  lay-filter="users" lay-allowclose="true" style="margin-bottom: 20px;">
                                <ul class="layui-tab-title">
                                    {foreach $list as $k => $user}
                                    <li {if($k===0)} class="layui-this" {/if}>{$k+1}</li>
                                    {/foreach}
                                </ul>
                                <div class="layui-tab-content" style="height: 200px;">
                                    {foreach $list as $k => $user}
                                    <div class="layui-tab-item {if($k === 0)} layui-show {/if}">
                                        <input type="hidden" value="{$user['id']}" name="ids[]" />
                                        <div class="form-group">
                                            <label class="col-sm-3 col-xs-3 control-label">顾客名称：</label>
                                            <div class="input-group col-sm-4 col-xs-8">
                                                <input type="text" class="form-control" required="" aria-required="true" value="{$user['name']}" readonly>
                                            </div>
                                        </div>
                                        <div class="form-group layui-form-item form-inline" style="height: 60px;">
                                            <label class="col-sm-3 col-xs-3 control-label">用户头像：</label>
                                            <div class="input-group col-sm-4 col-xs-8 ">
                                                <img src="{$user['headimgurl']}" width="40px" height="40px" />
                                            </div>
                                        </div>
                                        <div class="form-group">
                                            <label class="col-sm-3 col-xs-3 control-label">手机号：</label>
                                            <div class="input-group col-sm-4 col-xs-8">
                                                <input type="text" class="form-control" placeholder="" readonly value="{$user['mobile']}">
                                            </div>
                                        </div>
                                    </div>
                                    {/foreach}
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 col-xs-3 control-label">选择文案：</label>
                                <input type="hidden" name="message_type" id="message_type">
                                <div class="input-group col-sm-4 col-xs-8">
                                    <select lay-verify="required" lay-filter="message_list" lay-verify="required"
                                        lay-search="">
                                        <option value="">选择文案：</option>
                                        {foreach $message as $k => $m}
                                        <option value="{$k}">{$m['title']}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 col-xs-3 control-label">问候语</label>
                                <div class="input-group col-sm-4 col-xs-8">
                                    <select name="title" id="title"> </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 col-xs-3 control-label">项目作用</label>
                                <div class="input-group col-sm-4 col-xs-8">
                                    <textarea id="effect" name="effect" type="area" placeholder="请输入内容"
                                        class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-3 col-xs-3 control-label">注意事项</label>
                                <div class="input-group col-sm-4 col-xs-8">
                                    <textarea id="notice" name="notice" type="area" placeholder="请输入内容"
                                        class="layui-textarea"></textarea>
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-6">
                                    <button class="btn btn-primary" type="submit">推送</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <script src="__JS__/jquery.min.js?v=2.1.4"></script>
    <script src="__JS__/bootstrap.min.js?v=3.3.6"></script>
    <script src="__JS__/content.min.js?v=1.0.0"></script>
    <script src="__JS__/plugins/validate/jquery.validate.min.js"></script>
    <script src="__JS__/plugins/validate/messages_zh.min.js"></script>
    <script src="__JS__/plugins/layer/layer.min.js"></script>
    <script src="__JS__/layui/layui.js"></script>
    <script src="__JS__/jquery.form.js"></script>
    <script type="text/javascript">
        layui.use(['form', 'element'], function () {
            var form = layui.form, element = layui.element;
            form.on('select(message_list)', (value) => {
                $(this.item).val(value.value);
                $.getJSON('getMessage/key/' + value.value, {}, (data) => {
                    $('#message_type').val(data.title);
                    $('#effect').html(data.effect);
                    $('#notice').html(data.notice);
                    $('#title').html('').append(new Option(data.first, data.fitst), new Option(data.last, data.last));
                    form.render('select');
                })
            });

            element.on('tab(users)', (elem) => {
                // console.log(elem);
                // console.log( $(elem));
            });
        });

        var index = '';

        function showStart() {
            index = layer.load(0, {
                shade: false
            });
            return true;
        }

        function showSuccess(res) {

            layer.ready(function () {
                layer.close(index);
                if (1 == res.code) {
                    layer.alert(res.msg, {
                        title: '友情提示',
                        icon: 1,
                        closeBtn: 0
                    }, function () {
                        window.location.href = res.data;
                    });
                } else if (111 == res.code) {
                    window.location.reload();
                } else {
                    layer.msg(res.msg, {
                        anim: 6
                    });
                }
            });
        }

        $(document).ready(function () {
            // 添加管理员
            var options = {
                beforeSubmit: showStart,
                success: showSuccess
            };

            $('#commentForm').submit(function () {
                $(this).ajaxSubmit(options);
                return false;
            });
        });

        // 表单验证
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            },
            success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            },
            errorElement: "span",
            errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            },
            errorClass: "help-block m-b-none",
            validClass: "help-block m-b-none"
        });
    </script>
</body>

</html>